﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace GameLibrary.Map
{
    [Serializable]
    public static class MapHelper
    {            
        /// <summary>
        /// Find proper region map position.
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        public static Position FindRegion(Position pos)
        {
            int x = MathHelper.Floor(pos.X, GMHelper.RegionWidth);
            int y = MathHelper.Floor(pos.Y,GMHelper.RegionHeight);
            return new Position(x, y);
        }

        public static IEnumerable<Position> GetAdjacencyRegions(Position pos)
        {
            for(int i=-1;i<2;i++)
                for (int j = -1; j < 2; j++)
                {
                    Position position = new Position(i, j) + pos;

                    if (position.X < 0 || position.Y < 0
                        || position.X > GMHelper.Width || position.Y > GMHelper.Height // out of range
                        || position == pos) // not return self
                        continue;

                    yield return position;
                }
        }

        public static List<Position> surrondingPositions = new List<Position>{
            new Position(-1,-1),
            new Position(-1,0),
            new Position(-1,1),
       //     new Position(0,0),
            new Position(0,1),
            new Position(0,-1),
            new Position(1,0),
            new Position(1,1),
            new Position(1,-1)
        };
        public static ReadOnlyCollection<Position> SurrondingPositions
        {
            get
            {
                return new ReadOnlyCollection<Position>(surrondingPositions);
            }
        }

    }
}
